/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdAnalysisParameterConfigBo;
import com.comac.ins.isfd.domain.bo.IsfdOperatorBo;
import com.comac.ins.isfd.domain.bo.IsfdOperatorParameterMapDeleteBo;
import com.comac.ins.isfd.domain.bo.query.IsfdOperatorQueryBo;
import com.comac.ins.isfd.domain.vo.IsfdOperatorCountObjectVo;
import com.comac.ins.isfd.domain.vo.IsfdOperatorVo;
import com.comac.ins.isfd.domain.vo.IsfdRelatedOperatorInfoVo;
import com.comac.ins.isfd.service.IIsfdOperatorService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 算子controller
 *
 * @author hxloongs
 * @date 2024-7-9
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/operator")
public class IsfdOperatorController extends BaseController {
    @Autowired
    private IIsfdOperatorService iIsfdOperatorService;

    @SaCheckPermission("isfd:operator:count")
    @GetMapping("/list/count")
    @Operation(summary = "算子首页数量统计", security = @SecurityRequirement(name = "isfd:operator:count"))
    public R<List<IsfdOperatorCountObjectVo>> listCount() {
        return R.ok(iIsfdOperatorService.listCount());
    }

    @SaCheckPermission("isfd:operator:list")
    @PostMapping("/list")
    @Operation(summary = "算子列表查询接口", security = @SecurityRequirement(name = "isfd:operator:list"))
    public TableDataInfo<IsfdOperatorVo> list(@RequestBody IsfdOperatorQueryBo queryBo) {
        return iIsfdOperatorService.queryPageList(queryBo);
    }

    @SaCheckPermission("isfd:operator:detail")
    @GetMapping("/detail")
    @Operation(summary = "算子列表查询接口", security = @SecurityRequirement(name = "isfd:operator:detail"))
    public R<IsfdOperatorVo> queryDetail(@NotEmpty(message = "算子id不能为空") @RequestParam("operatorRefId") String operatorRefId) {
        return R.ok(iIsfdOperatorService.queryDetail(operatorRefId));
    }

    @SaCheckPermission("isfd:operator:add")
    @PostMapping(value = "/add")
    @Operation(summary = "算子添加", security = @SecurityRequirement(name = "isfd:operator:add"))
    public R<Void> add(@RequestBody IsfdOperatorBo isfdOperatorBo) {
        return toAjax(iIsfdOperatorService.add(isfdOperatorBo));
    }

    @SaCheckPermission("isfd:operator:update")
    @PostMapping(value = "/update")
    @Operation(summary = "算子修改", security = @SecurityRequirement(name = "isfd:operator:update"))
    public R<Void> update(@RequestBody IsfdOperatorBo isfdOperatorBo) {
        return toAjax(iIsfdOperatorService.update(isfdOperatorBo));
    }

    @SaCheckPermission("isfd:operator:remove")
    @Log(title = "算子删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/{operatorIds}")
    public R<Void> remove(@NotEmpty(message = "算子id不能为空")
                          @PathVariable String[] operatorIds) {
        return toAjax(iIsfdOperatorService.deleteWithValidByIds(List.of(operatorIds)));
    }


    @SaCheckPermission("isfd:operator:parameter:output:list")
    @GetMapping("/parameter/output/list")
    @Operation(summary = "映射关系页面-获取关联上下游参数名称列表接口", security = @SecurityRequirement(name = "isfd:operator:parameter:output:list"))
    public R<List<IsfdRelatedOperatorInfoVo>> parameterOutputList(@NotEmpty(message = "算子id不能为空") @RequestParam("operatorRefId") String operatorRefId,
                                                                  @NotEmpty(message = "算法id不能为空") @RequestParam("analysisRefId") String analysisRefId) {
        return R.ok(iIsfdOperatorService.parameterOutputList(operatorRefId, analysisRefId));
    }

    @SaCheckPermission("isfd:operator:parameter:map:add")
    @PostMapping(value = "/parameter/map/save")
    @Operation(summary = "新增上下游算子参数映射关系", security = @SecurityRequirement(name = "isfd:operator:parameter:map:add"))
    public R<Void> parameterMapSave(@RequestBody IsfdAnalysisParameterConfigBo isfdAnalysisParameterConfigBo) {
        return toAjax(iIsfdOperatorService.parameterMapSave(isfdAnalysisParameterConfigBo));
    }

    @SaCheckPermission("isfd:operator:parameter:map:update")
    @PostMapping(value = "/parameter/map/update")
    @Operation(summary = "修改已经配置的关系上游参数", security = @SecurityRequirement(name = "isfd:operator:parameter:map:update"))
    public R<Void> parameterMapUpdate(@RequestBody IsfdAnalysisParameterConfigBo isfdAnalysisParameterConfigBo) {
        return toAjax(iIsfdOperatorService.parameterMapUpdate(isfdAnalysisParameterConfigBo));
    }

    @SaCheckPermission("isfd:operator:parameter:map:delete")
    @Log(title = "删除已经配置的关系上游参数", businessType = BusinessType.DELETE)
    @PostMapping("/parameter/map/delete")
    public R<Void> parameterMapDelete(@RequestBody IsfdOperatorParameterMapDeleteBo isfdOperatorParameterMapDeleteBo) {
        return toAjax(iIsfdOperatorService.parameterMapDelete(isfdOperatorParameterMapDeleteBo));
    }
}
